using System;
using Handrise.BasicModal.Serialization.Interfaces;
using Handrise.BasicModal.Serialization.Attributes;
using System.Reflection;

namespace Handrise.BasicModal.Serialization.Surrogate
{
    /// <summary>
    /// Summary description for FakeSurrogate.
    /// </summary>
    public class DefaultSurrogates
    {
        #region ISurrogate Members

        [Attributes.Surrogate(typeof(System.DBNull))]
        public static Object DBNullSurrogate(Type t)
        {
            return DBNull.Value;
        }


        [Attributes.Surrogate(typeof(System.Collections.Hashtable))]
        [Attributes.Surrogate(typeof(System.Collections.ArrayList))]
        public static Object DefaultSurrogate(Type t)
        {
            Type[] arrt = new Type[0];
            ConstructorInfo ci = t.GetConstructor(arrt);
            if (ci == null) Console.WriteLine("No parameterless constructor available for object {0}", t);
            return ci.Invoke(null);
        }

        #endregion
    }
}
